package com.example.liang.basamovie.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.liang.basamovie.R;
import com.example.liang.basamovie.bean.SeleteItemBean;

import java.util.List;

/**
 * 搜索电影的适配器
 */
public class SeleteFilmAdapter extends RecyclerView.Adapter<SeleteFilmAdapter.MyViewHolder> {
    List<SeleteItemBean> list;
    Context context;

    public SeleteFilmAdapter(List<SeleteItemBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_selete_layout, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        SeleteItemBean seleteItemBean = list.get(position);
        holder.TitleName.setText(seleteItemBean.getTitle());

        holder.recyclerView.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false));
        SeleteFilmItemAdapter adapter = new SeleteFilmItemAdapter(seleteItemBean.getList(), context);
        holder.recyclerView.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView TitleName;
        RecyclerView recyclerView;
        public MyViewHolder(View itemView) {
            super(itemView);
            TitleName= (TextView) itemView.findViewById(R.id.Selete_TitleName);
            recyclerView= (RecyclerView) itemView.findViewById(R.id.seleteitem_RecyclerView);
        }
    }
}
